package com.homegoods.designer.ui.fragments;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.homegoods.designer.R;
import com.kedll.library.dialog.KBaseDialogFragment;
import com.kedll.library.util.StringUtil;
import com.kedll.library.util.ToastUtil;

/**
 * @author QiQi
 * @ClassName: AddSpaceFragment
 * @date 2018/10/7
 * @description 添加空间对话框
 */
public class AddSpaceFragment extends KBaseDialogFragment {

    private TextView mSpaceName;
    private View mSubmit;

    private OnConfirmClickListener onConfirmClickListener;

    public void setOnConfirmClickListener(OnConfirmClickListener onConfirmClickListener) {
        this.onConfirmClickListener = onConfirmClickListener;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Override
    protected void initEvent() {
        mSubmit.setOnClickListener(v -> {
            if (StringUtil.isEmpty(mSpaceName.getText())) {
                ToastUtil.showSnackbar(v, "请输入空间名称");
                return;
            }

            if (onConfirmClickListener != null) {
                onConfirmClickListener.onSubmit(mSpaceName.getText().toString());
            }
            dismiss();

        });
    }

    @Override
    protected void loadData(Bundle arguments) {

    }

    @Override
    protected int getLayout() {
        return R.layout.designer_dialog_add_space;
    }

    @Override
    protected void initView(View rootView) {
        mSpaceName = findViewById(R.id.ed_space_name);
        mSubmit = findViewById(R.id.btn_submit);
    }

    public interface OnConfirmClickListener {
        void onSubmit(String spaceName);
    }
}
